package com.cy.zs.hp.controller;


import com.cy.zs.hp.common.jsonResult.JsonResult;

import com.cy.zs.hp.controller.feign.service.IHisDoctorFeignService;
import com.cy.zs.hp.model.HisDoctor;
import com.cy.zs.hp.model.HisRegister;

import com.cy.zs.hp.service.IHisRegisterService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 该表处理预约登记 前端控制器
 * </p>
 *
 * @author cgb2008
 * @since 2020-11-28
 */
@RestController
@RequestMapping("/hp/hisRegister")
public class HisRegisterController {
    @Autowired
    private IHisRegisterService iHisRegisterService;


    @Autowired
    private IHisDoctorFeignService iHisDoctorFeignService;
    /*根据用户名查询预约患者*/
    @RequestMapping("/doFindRegister")
    public JsonResult doFindRegister(String username){
        return new JsonResult(iHisRegisterService.findRegister(username));
    }
    /*插入挂号患者表*/
    @RequestMapping("/doAddRegister")
    public JsonResult doAddRegister(@RequestBody HisRegister hisRegister){
        System.out.println(hisRegister.toString());
        int DoctorId = hisRegister.getDoctorId();
        String appointmentTime = hisRegister.getAppointmentTime();
        //远程调用查询查询医生信息
        com.cy.zs.web.util.JsonResult<HisDoctor> jsonDoctor = iHisDoctorFeignService.findByDoctorId(DoctorId);
        HisDoctor hisDoctor = jsonDoctor.getData();
        String doctorName = hisDoctor.getDoctorName();
        String department = hisDoctor.getDepartment();
        hisRegister.setDoctorName(doctorName);
        hisRegister.setDepartmentName(department);
        iHisRegisterService.insertRegister(hisRegister);
        iHisDoctorFeignService.setdoctor(DoctorId, appointmentTime);//向工作表中添加参数
        return new JsonResult("预约完成");
    }
    @GetMapping("/{doctorId}/{patientId}")//String doctorId, String patientId
    public JsonResult findByDoctorId(@PathVariable String doctorId, @PathVariable String patientId){
        Integer id = Integer.valueOf(doctorId);
        Integer pId = Integer.valueOf(patientId);
        List<HisRegister> list = iHisRegisterService.findByDoctorId(id, pId);
        return new JsonResult(list);
    }

}
